/*
 * Copyright (C) 2022 KylinSoft Co., Ltd.
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <https://www.gnu.org/licenses/>.
 */

#ifndef DATABASESQL_H
#define DATABASESQL_H

#define CREATE_TABLE_ITEMLIST "CREATE TABLE itemlist ("\
                                "itemId integer primary key NOT NULL, "\
                                "desktopName varchar, "\
                                "name varchar, "\
                                "iconName varchar, "\
                                "type integer NOT NULL, "\
                                "placeholder varchar NOT NULL, "\
                                "categories varchar NOT NULL)"

#define CREATE_TABLE_SETS "CREATE TABLE sets ("\
                            "id integer primary key NOT NULL, "\
                            "setId integer NOT NULL, "\
                            "sequence varchar, "\
                            "titleEditable varchar, "\
                            "containerEditable varchar, "\
                            "containerCategory varchar)"

#define CREATE_TABLE_PAGE "CREATE TABLE page ("\
                            "pageId integer primary key NOT NULL, "\
                            "sequence varchar)"

#define SELECT_ITEMLIST_BY_DESKTOPNAME "SELECT * FROM itemlist WHERE desktopName=:desktopName"
#define SELECT_ITEMLIST "SELECT * FROM itemlist"
#define SELECT_SETS "SELECT * FROM sets"
#define SELECT_PAGE "SELECT * FROM page"
#define SELECT_ITEMLIST_BY_ID "SELECT * FROM itemlist WHERE id=:id"
#define SELECT_SETS_BY_SETID "SELECT * FROM sets WHERE setId=:setId"
#define SELECT_PAGE_BY_PAGEID "SELECT * FROM page WHERE pageId=:pageId"
#define SELECT_ITEMLIST_BY_DESKTOPNAME "SELECT * FROM itemlist WHERE desktopName=:desktopName"
#define SELECT_ITEMLIST_BY_ITEMID "SELECT * FROM itemlist WHERE itemId=:itemId"

#define UPDATE_ITEMLIST "UPDATE itemlist SET desktopName=?, name=?, iconName=?, categories=? WHERE itemId=?"
#define UPDATE_SETS "UPDATE sets SET sequence=? WHERE setId=?"
#define UPDATE_ITEMLIST_NAME_ITEMID "UPDATE itemlist SET name=? WHERE itemId=?"
#define UPDATE_PAGE "UPDATE page SET sequence=? WHERE pageId=?"

#define INSERT_ITEMLIST "INSERT INTO itemlist (itemId, desktopName, name, iconName, type, placeholder, categories) "\
                                        "VALUES (?, ?, ?, ?, ?, ?, ?)"
#define INSERT_SETS "INSERT INTO sets (setId, sequence, titleEditable, containerEditable, containerCategory) "\
                                        "VALUES (?, ?, ?, ?, ?)"
#define INSERT_PAGE "INSERT INTO page (sequence, pageId) VALUES (?, ?)"
#define DELETE_ITEMLIST_BY_ITEMID "DELETE FROM itemlist WHERE itemId = %1"
#define DELETE_PAGE_BY_PAGEID "DELETE FROM page WHERE pageId = %1"
#define DELETE_ITEMLIST_BY_ID "DELETE FROM itemlist WHERE id = %1"
#define DELETE_SETS_BY_SETID "DELETE FROM sets WHERE setId = %1"
#define DROP_TABLE_BY_TABLENAME "DROP TABLE %1"
#define DELETE_TABLEDATA_BY_TABLENAME "DELETE FROM %1"


#define VAR_TO_FIELD(var) #var

#define ITEMLIST_TABLE_FIELDS_COUNT  7
#define PAGE_TABLE_FIELDS_COUNT 2
#define SETS_TABLE_FIELDS_COUNT 6

const char *itemListTableFields[ITEMLIST_TABLE_FIELDS_COUNT]  = {
    "itemId", "desktopName", "name", "iconName", "type", "placeholder", "categories"
};

const char *pageTableFields[PAGE_TABLE_FIELDS_COUNT]  = {
    "pageId", "sequence",
};

const char *setsTableFields[SETS_TABLE_FIELDS_COUNT]  = {
    "id", "setId", "sequence", "titleEditable", "containerEditable", "containerCategory"
};

#endif // DATABASESQL_H
